<template>
  <h1 class="manageTitle">广东海洋大学人员管理系统</h1>
  <div class="login-wrapper">
    <div class="back"><img src="./../assets/images/Welcome.jpeg" alt=""></div>
    <div class="modal">
      <el-form ref="userFrom" :model="user" status-icon :rules="rules">
        <div class="title">登录</div>
        <el-form-item prop="userName">
          <el-input type="text" prefix-icon="el-icon-user" v-model="user.userName"></el-input>
        </el-form-item>

        <el-form-item prop="userPwd">
          <el-input type="password" prefix-icon="el-icon-view" v-model="user.userPwd"></el-input>
        </el-form-item>

        <el-form-item>
         <el-button class="btn-login" type="primary" @click="login">登录</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  name: "Login",
  data(){
    return{
      //登陆用户信息
      user:{
        userName: '',
        userPwd: '',
      },
      // 校验
      rules:{
        userName: [
          {
          required:true,message:"请输入用户名",trigger:"blur"
          }
        ],
        userPwd: [
          {
            required:true,message:"请输入密码",trigger:"blur"
          }
        ]
      }
    }
  },
  methods:{
    //登陆方法
    login(){
      this.$refs.userFrom.validate((valid)=>{
        if (valid){
          this.$api.login(this.user).then((res)=>{
            this.$store.commit('saveUserInfo',res)
            this.$router.push('/welcome')
          })
        }else {
          return false
        }
      })
    }
  }
}

</script>

<style lang="scss">
.manageTitle{
  width: 100%;
  height: 100px;
  line-height: 150px;
  text-align: center;
  letter-spacing: 5px;
  font-size: 40px;
  color: #409eff;
  font-weight: 700;
  background-color: #f9fcff;
}
.login-wrapper {
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #f9fcff;
  width: 100vw;
  height: 85vh;
  .back{
    width: 500px;
    height: 327px;
    overflow: hidden;
    margin-right: 100px;
    border-radius: 20px;
    box-shadow: 0 0  10px 3px #c7c9cb4d;
    img{
      width: 500px;
      height: 327px;
      overflow: clip;
    }
  }
  .modal {
    width: 500px;
    padding: 50px;
    background-color: #fff;
    border-radius: 4px;
    box-shadow: 0 0  10px 3px #c7c9cb4d;
    .title {
      font-size: 30px;
      line-height: 1.5;
      text-align: center;
      margin-bottom: 30px;
    }
    .btn-login {
      width: 100%;
    }
  }
}
</style>
